//
//  zhiFuNewSSSViewController.m
//  shopping
//
//  Created by 马田成 on 2017/9/25.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "zhiFuNewSSSViewController.h"
#import "zhiFuMMView.h"
#import "aaaaaaaaaaaaaViewController.h"
#import "ModifierPasswordController.h"
@interface zhiFuNewSSSViewController ()

{

    NSString *moneyType;
    UIView *grayView;
  //  NSString *lilv;
    

}

@property (weak, nonatomic) IBOutlet UILabel *shangCheng;
@property (nonatomic, strong) NSMutableDictionary *dataDic;
@property (weak, nonatomic) IBOutlet UILabel *jiaoYi;
@property (weak, nonatomic) IBOutlet UIImageView *shangChengImg;
@property (weak, nonatomic) IBOutlet UIImageView *jiaoYiImg;
@property (weak, nonatomic) IBOutlet UILabel *lexiangBi;
@property (weak, nonatomic) IBOutlet UILabel *leXiang;
@property (weak, nonatomic) IBOutlet UIImageView *leXiangImg;
@property (weak, nonatomic) IBOutlet UIView *leXiangView;
@property (weak, nonatomic) IBOutlet UIButton *lexiangButton;
@property (weak, nonatomic) IBOutlet UIButton *queRenButton;
@property (nonatomic, strong) zhiFuMMView *zhiFuMMView;
@property (weak, nonatomic) IBOutlet UIButton *shangChengButton;
@property (weak, nonatomic) IBOutlet UIButton *jiaoyiButton;
@property (weak, nonatomic) IBOutlet UILabel *leXiangNew;
@property (weak, nonatomic) IBOutlet UILabel *jiaoyiKaiN;
@property (weak, nonatomic) IBOutlet UIView *jiaoyiViewN;

@end

@implementation zhiFuNewSSSViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    [self creationDDDDD];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"支付"];

    moneyType = @"1";
    
    // Do any additional setup after loading the view from its nib.
}

- (void)creationDDDDD{

    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:adminLxlpersonJudgePaypwd networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"code"]intValue]==-1) {
            
            [self creationData];
            
        }
        else {
            
            
         //   self.view.hidden = YES;
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            ModifierPasswordController *vc2 = [[ModifierPasswordController alloc] init];
            vc2.hidesBottomBarWhenPushed = YES;
            
            [self.navigationController pushViewController:vc2 animated:YES];
            
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        //            [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];



}



- (void)creationData{
    
    _dataDic = [[NSMutableDictionary alloc] init];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    //    [productParams setValue:self.orderId forKey:@"orderId"];
    [productParams setValue:self.orderId forKey:@"orderId"];
    [[MNetworkHandler sharedInstance]conURL:adminorderPaymentUserMoney networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            self.dataDic = [returnData objectForKey:@"data"];
            
            
            NSString *str = @"确认支付";
            
            [self.queRenButton setTitle:[str stringByAppendingString:self.money] forState:UIControlStateNormal];
            
            
            
            if ([[self.dataDic objectForKey:@"type"] isEqualToString:@"3"]) {
                
                NSString *str2222 = @"(";
                NSString *str3333 = @")";
                self.shangCheng.text = [[[[self.dataDic objectForKey:@"money_shangcheng_new"] stringByAppendingString:str2222] stringByAppendingString:@"90%"] stringByAppendingString:str3333];
                self.leXiangNew.text = @"购物锎";
                
                
                self.leXiang.text = [self.dataDic objectForKey:@"money_lvyou"];
                
                self.jiaoYi.text = [[[[self.dataDic objectForKey:@"money_jiaoyi"] stringByAppendingString:str2222] stringByAppendingString:@"10%"] stringByAppendingString:str3333];
                self.jiaoyiKaiN.text = @"乐享锎";
                
                
                self.shangChengImg.image = [UIImage imageNamed:@"shouhuo_xuanzhong"];
                self.jiaoYiImg.image = [UIImage imageNamed:@"shouhuo_xuanzhong"];
                self.leXiangImg.hidden = YES;
                self.leXiangView.hidden = YES;
                self.lexiangBi.hidden = YES;
                self.lexiangButton.hidden = YES;
                self.leXiang.hidden = YES;
                
                
                [self.shangChengButton setEnabled:NO];
                [self.lexiangButton setEnabled:NO];
                [self.jiaoyiButton setEnabled:NO];
                
                
                
            }else  if ([[self.dataDic objectForKey:@"type"] isEqualToString:@"1"]){
            
                self.leXiangNew.text = @"购物锎";
                self.jiaoyiKaiN.text = @"乐享锎";
                self.shangCheng.text = [self.dataDic objectForKey:@"money_shangcheng_new"];
                self.jiaoYi.text = [self.dataDic objectForKey:@"money_jiaoyi"];
                
                self.leXiang.hidden = YES;
                self.leXiangImg.hidden = YES;
                self.leXiangView.hidden = YES;
                self.lexiangBi.hidden = YES;
                self.lexiangButton.hidden = YES;
                
                
            }else{
            
                self.shangCheng.text = [self.dataDic objectForKey:@"money_jiaoyi"];
                self.leXiangNew.text = @"乐享锎";
                self.jiaoYi.hidden = YES;
                self.jiaoYiImg.hidden = YES;
                self.jiaoyiKaiN.hidden = YES;
                self.jiaoyiViewN.hidden = YES;
                
                self.leXiang.hidden = YES;
                self.leXiangImg.hidden = YES;
                self.leXiangView.hidden = YES;
                self.lexiangBi.hidden = YES;
                self.lexiangButton.hidden = YES;
                
            }

        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
}
- (IBAction)queRenClick:(UIButton *)sender {
    
    grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
    grayView.backgroundColor = [UIColor colorWithRed:0 / 255.0f green:0 / 255.0f blue:0 / 255.0f alpha:0.2];
    
    [[UIApplication sharedApplication].keyWindow addSubview:grayView];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissContactView)];
    [grayView addGestureRecognizer:tapGesture];
    _zhiFuMMView = [[NSBundle mainBundle] loadNibNamed:@"zhiFuMMView" owner:self options:nil].lastObject;
    [grayView addSubview:self.zhiFuMMView];
    self.zhiFuMMView.backgroundColor = [UIColor whiteColor];
    [self.zhiFuMMView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(150);
        make.height.offset(140);
        make.width.offset(300);
        make.centerX.equalTo(self.view.mas_centerX);
        
    }];
    
    
    [self.zhiFuMMView.quXiaoBtn addTarget:self action:@selector(dismissContactView) forControlEvents:UIControlEventTouchUpInside];
    
    [self.zhiFuMMView.queRenBtn addTarget:self action:@selector(zhiFuMoney) forControlEvents:UIControlEventTouchUpInside];

    
    
}
- (void)zhiFuMoney{

    if ([[self.dataDic objectForKey:@"type"] isEqualToString:@"3"]){
        
        NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
        NSString *token = [PublicFunction getConfigWithKey:@"token"];
        // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
        
        [productParams setValue:token forKey:@"token"];
        //    [productParams setValue:self.orderId forKey:@"orderId"];
        [productParams setValue:self.orderId forKey:@"str_orderId"];
      //  [productParams setValue:moneyType forKey:@"use_currency"];
        [productParams setValue:self.zhiFuMMView.zhiFuTF.text forKey:@"payPwd"];
        //  [productParams setValue:lilv forKey:@"rate"];
        [[MNetworkHandler sharedInstance]conURL:adminorderSetMoneyNew networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
            
            if ([[returnData objectForKey:@"code"]intValue]==1) {
                
                
                [self dismissContactView];
                
                aaaaaaaaaaaaaViewController * vc = [[aaaaaaaaaaaaaViewController alloc] init];
                vc.type = @"1";
                [self.navigationController pushViewController:vc animated:YES];
                
                
            }
            
            else {
                
                [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                
            }
            
        } failureBlock:^(NSError *error) {
            
            NSLog(@"%@",error);
            
//            [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
            
        }];

        
        
        
    
    }else  if ([[self.dataDic objectForKey:@"type"] isEqualToString:@"1"]){
    
        NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
        NSString *token = [PublicFunction getConfigWithKey:@"token"];
        // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
        
        [productParams setValue:token forKey:@"token"];
        //    [productParams setValue:self.orderId forKey:@"orderId"];
        [productParams setValue:self.orderId forKey:@"str_orderId"];
        [productParams setValue:moneyType forKey:@"use_currency"];
        [productParams setValue:self.zhiFuMMView.zhiFuTF.text forKey:@"payPwd"];
        //  [productParams setValue:lilv forKey:@"rate"];
        [[MNetworkHandler sharedInstance]conURL:adminorderSetMoney networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
            
            if ([[returnData objectForKey:@"code"]intValue]==1) {
                
                
                [self dismissContactView];
                
                aaaaaaaaaaaaaViewController * vc = [[aaaaaaaaaaaaaViewController alloc] init];
                vc.type = @"1";
                [self.navigationController pushViewController:vc animated:YES];
                
                
            }

            
            else {
                
                [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                
            }
            
        } failureBlock:^(NSError *error) {
            
            NSLog(@"%@",error);
            
//            [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
            
        }];

        
    }else {
        NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
        NSString *token = [PublicFunction getConfigWithKey:@"token"];
        // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
        
        [productParams setValue:token forKey:@"token"];
        //    [productParams setValue:self.orderId forKey:@"orderId"];
        [productParams setValue:self.orderId forKey:@"str_orderId"];
        [productParams setValue:@"2" forKey:@"use_currency"];
        [productParams setValue:self.zhiFuMMView.zhiFuTF.text forKey:@"payPwd"];
        //  [productParams setValue:lilv forKey:@"rate"];
        [[MNetworkHandler sharedInstance]conURL:adminorderSetMoney networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
            
            if ([[returnData objectForKey:@"code"]intValue]==1) {
                
                
                [self dismissContactView];
                
                aaaaaaaaaaaaaViewController * vc = [[aaaaaaaaaaaaaViewController alloc] init];
                vc.type = @"1";
                [self.navigationController pushViewController:vc animated:YES];
                
                
            }

            
            else {
                
                [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                
            }
            
        } failureBlock:^(NSError *error) {
            
            NSLog(@"%@",error);
            
//            [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
            
        }];

        
    
        
    
    }
    
    

}

- (void)dismissContactView {
    [grayView removeFromSuperview];
}



- (IBAction)shangChengClick:(UIButton *)sender {
    moneyType = @"1";
    self.shangChengImg.image = [UIImage imageNamed:@"shouhuo_xuanzhong"];
    self.jiaoYiImg.image = [UIImage imageNamed:@"shouhuo_meiyou"];
    self.leXiangImg.image = [UIImage imageNamed:@"shouhuo_meiyou"];
    
}
- (IBAction)jiaoYiClick:(UIButton *)sender {
    moneyType = @"2";
    self.shangChengImg.image = [UIImage imageNamed:@"shouhuo_meiyou"];
    self.jiaoYiImg.image = [UIImage imageNamed:@"shouhuo_xuanzhong"];
    self.leXiangImg.image = [UIImage imageNamed:@"shouhuo_meiyou"];
    
    
}
- (IBAction)leXiangClick:(UIButton *)sender {
    moneyType = @"3";
    self.shangChengImg.image = [UIImage imageNamed:@"shouhuo_meiyou"];
    self.jiaoYiImg.image = [UIImage imageNamed:@"shouhuo_meiyou"];
    self.leXiangImg.image = [UIImage imageNamed:@"shouhuo_xuanzhong"];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
